// ********************************************************************************************************
// Figure C2: Employment over parcel size and building footprint over parcel size by NAICS 3-digit industry
// ********************************************************************************************************

// Writes the results as reg_montreal to $resultpath/figures/

set scheme s2color

//Employment over parcel size

use "$outpath/database_for_reg.dta", clear

eststo clear

gen ind_dens=employment*1000/P_area_c
label var ind_dens "Employment over parcel size (per 1,000 of sq meter)"

reghdfe Lnland_pwc Lnpopcma Lnareacma dist_min_NEW i.cat0 spacematep spacematep2 spacematep3 spacematep4 if samplep==1, absorb(naics4d eruid) cluster(cmauid)

keep if e(sample)==1

tostring naics3d, replace

replace naics3d="311 Food manufacturing" if naics3d=="311"
replace naics3d="312 Beverage product manuf." if naics3d=="312"
replace naics3d="313 Textile mills" if naics3d=="313"
replace naics3d="314 Textile product mills" if naics3d=="314"
replace naics3d="315 Clothing manufacturing" if naics3d=="315"
replace naics3d="316 Leather, allied product manuf." if naics3d=="316"
replace naics3d="321 Wood product manufacturing" if naics3d=="321"
replace naics3d="322 Paper manufacturing" if naics3d=="322"
replace naics3d="323 Printing, support activities" if naics3d=="323"
replace naics3d="324 Petrol, coal product manuf." if naics3d=="324"
replace naics3d="325 Chemical manufacturing" if naics3d=="325"
replace naics3d="326 Plastics, rubber products manuf." if naics3d=="326"
replace naics3d="327 Non-metallic mineral product manuf." if naics3d=="327"
replace naics3d="331 Primary metal manufacturing" if naics3d=="331"
replace naics3d="332 Fabricated metal product manuf." if naics3d=="332"
replace naics3d="333 Machinery manufacturing" if naics3d=="333"
replace naics3d="334 Computer, electronic product manuf." if naics3d=="334"
replace naics3d="335 Electrical, appliance manuf." if naics3d=="335"
replace naics3d="336 Transportation equipment manuf." if naics3d=="336"
replace naics3d="337 Furniture, related product manuf." if naics3d=="337"
replace naics3d="339 Miscellaneous manufacturing" if naics3d=="339"

graph hbox ind_dens, over(naics3digit, lab(labsize(small))) nooutsides note("") medtype(line)  /// 
box(1, fcolor(white) lcolor(black)) name(gr1, replace) ytitle("Employment over parcel size (per 1,000 of sq meters)", size(small))
graph export "$resultpath/figures/desc_ind_dens.pdf", replace

//Building footprint over parcel size

use "$outpath/database_for_reg.dta", clear

gen parc_cov=B_area_c/P_area_c
label var parc_cov "Building footpring over parcel size"


reghdfe ratio Lnpopcma Lnareacma dist_min_NEW i.cat0 spacematep spacematep2 spacematep3 spacematep4 if samplep==1, absorb(naics4d eruid) cluster(cmauid)

keep if e(sample)==1&parc_cov<1

tostring naics3d, replace

replace naics3d="311 Food manufacturing" if naics3d=="311"
replace naics3d="312 Beverage product manuf." if naics3d=="312"
replace naics3d="313 Textile mills" if naics3d=="313"
replace naics3d="314 Textile product mills" if naics3d=="314"
replace naics3d="315 Clothing manufacturing" if naics3d=="315"
replace naics3d="316 Leather, allied product manuf." if naics3d=="316"
replace naics3d="321 Wood product manufacturing" if naics3d=="321"
replace naics3d="322 Paper manufacturing" if naics3d=="322"
replace naics3d="323 Printing, support activities" if naics3d=="323"
replace naics3d="324 Petrol, coal product manuf." if naics3d=="324"
replace naics3d="325 Chemical manufacturing" if naics3d=="325"
replace naics3d="326 Plastics, rubber products manuf." if naics3d=="326"
replace naics3d="327 Non-metallic mineral product manuf." if naics3d=="327"
replace naics3d="331 Primary metal manufacturing" if naics3d=="331"
replace naics3d="332 Fabricated metal product manuf." if naics3d=="332"
replace naics3d="333 Machinery manufacturing" if naics3d=="333"
replace naics3d="334 Computer, electronic product manuf." if naics3d=="334"
replace naics3d="335 Electrical, appliance manuf." if naics3d=="335"
replace naics3d="336 Transportation equipment manuf." if naics3d=="336"
replace naics3d="337 Furniture, related product manuf." if naics3d=="337"
replace naics3d="339 Miscellaneous manufacturing" if naics3d=="339"


graph hbox parc_cov, over(naics3digit, lab(labsize(small))) nooutsides note("") medtype(line)  /// 
box(1, fcolor(white) lcolor(black)) name(gr1, replace) ytitle("Building footprint over parcel size (per 1,000 of sq meters)", size(small))
graph export "$resultpath/figures/desc_parc_cov.pdf", replace
